#include <iostream>
#include <utmp.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define SHOWHOST ;
void show_info(utmp* record){
    if(record == NULL){
        cout << "info error\n";
        exit(-1);
    }
    if(record->ut_type != USER_PROCESS){
        return;
    }
    printf("%-8.8s",record->ut_user);
    printf(" ");
    printf("%-8.8s",record->ut_line);
    printf(" ");
    printf("20%s",record->ut_id);
    printf(" ");
#ifdef SHOWHOST
    printf("(10%s)",record->ut_host);
#endif
    printf("\n");

}

int main()
{
    struct utmp current_record;
    int fd;
    size_t size_record = sizeof(current_record);
    fd = open(UTMP_FILE,O_RDONLY);
    if(fd == -1){
        cout << "open UTMP_FILE error;\n";
        exit(-1);
    }
    while(read(fd,&current_record,size_record) == size_record){
        show_info(&current_record);
    }
    close(fd);
    return 0;
}
